﻿Imports System.Data
Imports System.Data.SqlClient
Public Class Form6
    Sub Carga_Licitaciones()
        Dim SQL As String = "SELECT l.Cod_licitacion, l.Descripcion, l.Fecha_registro, l.Fecha_inicio, l.Fecha_fin, l.Responsable, e.Descripcion'Estado' FROM Licitacion l " & _
                            " INNER JOIN Estado e ON e.Cod_Estado=l.Cod_Estado" & _
                            " WHERE l.Cod_Estado='01' ORDER BY l.Cod_licitacion ASC"
        Dim da As SqlDataAdapter
        Dim dt As New DataTable
        Try
            da = New SqlDataAdapter(SQL, nCnn)
            da.Fill(dt)
            ListView1.Items.Clear()
            For i = 0 To dt.Rows.Count - 1
                Dim Itm = ListView1.Items.Add(RTrim(dt.Rows(i)("Cod_licitacion")))
                Itm.SubItems.Add(RTrim(dt.Rows(i)("Descripcion")))
                Itm.SubItems.Add(RTrim(dt.Rows(i)("Fecha_registro")))
                If IsDBNull(dt.Rows(i)("Fecha_inicio")) Then
                    Itm.SubItems.Add("")
                Else
                    Itm.SubItems.Add(RTrim(dt.Rows(i)("Fecha_inicio")))
                End If
                Itm.SubItems.Add(RTrim(dt.Rows(i)("Fecha_fin")))
                Itm.SubItems.Add(RTrim(dt.Rows(i)("Responsable")))
                Itm.SubItems.Add(RTrim(dt.Rows(i)("Estado")))
            Next
            ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub
    Private Sub Form6_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Call Carga_Licitaciones()
    End Sub

    Private Sub ListView1_DoubleClick(sender As Object, e As EventArgs) Handles ListView1.DoubleClick
        For i = 0 To ListView1.Items.Count - 1
            If ListView1.Items(i).Selected = True Then
                Licitacion = ListView1.Items(i).SubItems(0).Text
                Form3.MdiParent = MDIParent1
                Form3.Show()
            End If
        Next
    End Sub

    Private Sub ListView1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles ListView1.KeyPress
        If Asc(e.KeyChar) = 13 Then
            For i = 0 To ListView1.Items.Count - 1
                If ListView1.Items(i).Selected = True Then
                    Licitacion = ListView1.Items(i).SubItems(0).Text
                    Form3.MdiParent = MDIParent1
                    Form3.Show()
                End If
            Next
        End If
    End Sub

    Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.SelectedIndexChanged
        
    End Sub
End Class